package com.youlu.campus.web.ads.controller;

import com.youlu.campus.service.ad.UserAdsRecordService;
import com.youlu.campus.web.common.base.RequestContext;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class UserAdController {
    @Autowired
    private UserAdsRecordService userAdsRecordService;

    @PostMapping("/mini-app/user-ads/start")
    public QResult startViewAd(@RequestParam("adId") String adId) {
        return QResult.success(userAdsRecordService.startViewAd(RequestContext.getUserId(), adId, RequestContext.getCurPlatform(), RequestContext.getAppId(), new Date()));
    }

    @PostMapping("/mini-app/user-ads/end")
    public QResult endviewAd(@RequestParam("id") String id) {
        return QResult.success(userAdsRecordService.endViewAd(RequestContext.getCurUser(), id,
                RequestContext.getAppId(), RequestContext.getCurPlatform()));
    }

    @PostMapping("/mini-app/task/user-ads/start")
    public QResult startTaskViewAd(@RequestParam("adId") String adId,@RequestParam("activityId")String activityId) {
        return QResult.success(userAdsRecordService.startTaskViewAd(activityId,RequestContext.getUserId(), adId, RequestContext.getCurPlatform(), RequestContext.getAppId()));
    }

    @PostMapping("/mini-app/task/user-ads/end")
    public QResult endTaskViewAd(@RequestParam("id") String id) {
        userAdsRecordService.endTaskViewAd(RequestContext.getCurUser(), id);
        return QResult.success(null);
    }
}
